/*  
     PlAr is Platform Arena: a 2D multiplayer shooting game
     Copyright (C) 2009 Ragagnin Antonio <spocchio@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package plar.core;

import plar.core.Action;
import plar.core.Common;
import plar.core.Element;
import plar.core.Level;
import plar.core.Parameters;

public class LifeTimer implements Action {
	int time=-2;
	
	
	public Parameters call(Parameters parameters) {
		if(time==-2)
		{
						Element me = (Element) parameters.get("me");
						
						time = (Integer) me.getProperty("lifeTime");
						
		}
		
		String subAction = (String) parameters.get("subAction");
		
		
		if (subAction == "main" && time!=-1) {
			time--;
			if(time<=0)
			{
						Element me = (Element) parameters.get("me");
						Level level = me.level;
						parameters.put("subAction", "new");
						parameters.put("me", me);
						parameters.put("level", level);
						me.actions.runAction("destroy", parameters);
			}
		}
	
		return null;
	}

}
